package com.a3dweijing.wetouch2.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.ImageLoaderUtil;
import com.a3dweijing.wetouch2.bean.Special;

import java.util.List;

/**
 * @author wuzhen
 * @since 2017/07/24
 */
public class SampleAdapter extends PagerAdapter {
    private List<Special> specials;

    public SampleAdapter(List<Special> specials) {
        this.specials = specials;
    }

    @Override
    public int getCount() {
        return specials.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(container.getContext(), R.layout.item_special_top, null);
        ImageView iv = (ImageView) view.findViewById(R.id.special_top_rec_pic);
        ImageLoaderUtil.getLoader().loadImg2(specials.get(position%specials.size()).getSpecial_topic_img(),iv);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object != null && object instanceof View) {
            container.removeView((View) object);
        }
    }
}
